{extend name="main"}
{block name="style"}
<style type="text/css">
	.flex-lable{width: 140px;color: #6c757d;text-align: right;padding-right: 10px;}
	.tag-color0,.tag-color0 .el-link--inner{color: #aaaaaa !important;}
	.tag-color1,.tag-color1 .el-link--inner{color: #ff9999 !important;}
	.tag-color2,.tag-color2 .el-link--inner{color: #ff4a4a !important;}
	.tag-color3,.tag-color3 .el-link--inner{color: #ff0000 !important;}
	.tag-color4,.tag-color4 .el-link--inner{color: #FF6D05 !important;}
</style>
{/block}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right">
		<div class="flex py-3">

	  <el-form-item label="搜索类型" prop="search_type" class="flex mb-0 pl-3">
	  	<el-select v-model="search.search_type" placeholder="请选择" class="w-100px">
		    <el-option label="公司ID"value="id"></el-option>
		    <el-option label="UID"value="uid"></el-option>
		    <el-option label="统一社会信用代码"value="uscc"></el-option>
		    <el-option label="公司名"value="company_name"></el-option>
		    <el-option label="手机号"value="customer_mobile"></el-option>
		    <el-option label="座机"value="customer_tel"></el-option>
		    <el-option label="邮箱"value="customer_email"></el-option>
		    <el-option label="微信号"value="customer_wechat"></el-option>
		    <el-option label="QQ"value="customer_qq"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="企业认证" prop="attestation" class="flex mb-0 pl-3">
	  	<el-select v-model="search.attestation" placeholder="请选择" class="w-100px">
		    <el-option key="all"label="全部"value="all"></el-option>
		    <el-option v-for="v in attestation" :key="v.value":label="v.title":value="v.value"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item :label="getSearchType()" prop="key" class="flex mb-0 pl-3">
	    <el-input v-model="search.key" placeholder="请输入你想搜索的关键词"></el-input>
	  </el-form-item>

	  <el-form-item prop="follow_up" class="flex mb-0 pl-3">
	  	<el-checkbox v-model="search.follow_up" true-label="today" false-label="all">今日待跟进</el-checkbox>
	  </el-form-item>

		  <el-form-item class="flex mb-0 pl-3">
		    <el-button type="primary" @click="initHtml">查询</el-button>
		    <el-button @click="resetForm('search')">重置</el-button>
		    <el-button type="text" @click="seniorSearch= !seniorSearch">更多搜索<i class="el-icon-arrow-up el-icon--right" v-if="seniorSearch"></i><i class="el-icon-arrow-down el-icon--right" v-else></i></el-button>
		  </el-form-item>
			
		</div>
		<transition>
		<div class="pb-3" v-show="seniorSearch">
	  
		  <el-form-item label="会员" prop="vip_level" label-width="120px">
		  	<el-select v-model="search.vip_level" filterable placeholder="请选择">
			    <el-option label="全部"value="all"></el-option>
			    <el-option
			      v-for="item in vip"
			      :key="item.level"
			      :label="item.title"
			      :value="item.level"
			       v-if="item.is_company">
			    </el-option>
			</el-select>
		  </el-form-item>
	  
		  <el-form-item label="标签" prop="tag" label-width="120px">
		  	<el-select v-model="search.tag" filterable placeholder="请选择">
			    <el-option label="全部"value="all"></el-option>
			    <el-option
			      v-for="item in CrmTag"
			      :key="item.value"
			      :label="item.title"
			      :value="item.value">
			    </el-option>
			</el-select>
		  </el-form-item>
		{eq name=":request()->action()" value="customer"}
	  <el-form-item label="所有者" prop="adviser_id" label-width="120px">
		  <el-select
		    v-model="search.adviser_id"
		    filterable
		    placeholder="所有者"
		    clearable>
		    <el-option
		      v-for="item in admin"
		      :key="item.id"
		      :label="item.nickname"
		      :value="item.id">
		    </el-option>
		  </el-select>
	  </el-form-item>
	  {/eq}
		</div>
		</transition>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive">
		<el-table
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB"
    		@selection-change="handleSelectionChange">
		  <el-table-column
			  type="selection"
			  width="55">
		  </el-table-column>
	      <el-table-column
	      	prop="title"
	        label="客户名称/下次跟进时间"
	        width="300">
			  <template slot-scope="scope">
			  	<div>
			  	<el-link :href="'/company?id='+scope.row.company_id" target="_blank" :underline="false"
			  	:class="'tag-'+scope.row.tag_type">{{scope.row.title}}</el-link>
			  	<div>
			  		<span class="text-success" v-if="scope.row.is_next_today" size="mini">今日待跟进</span>
			  		<span class="text-secondary" v-else-if="scope.row.next_follow_up_time_date" size="mini"
			  		title="下次跟进时间">{{scope.row.next_follow_up_time_date}}</span>
			  	</div>
			  	</div>
			  </template>
	      </el-table-column>
		  <el-table-column type="expand" width="20">
			  <template slot-scope="scope">
			      <div class="small">
		      		<p>联系人：{{scope.row.customer}}</p>
			      	<p>手机号：{{scope.row.customer_mobile}}</p>
			      	<p>座机：{{scope.row.customer_tel}}</p>
			      	<p>邮箱：{{scope.row.customer_email}}</p>
			      	<p>微信号：{{scope.row.customer_wechat}}</p>
			      	<p>QQ：{{scope.row.customer_qq}}</p>
			      	<p>其他：{{scope.row.customer_other}}</p>
			      </div>
			  </template>
		  </el-table-column>
	      <el-table-column
	        label="联系方式"
	        width="180">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div>联系人：{{scope.row.customer}}</div>
		      	<div>手机号：{{scope.row.customer_mobile}}</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="vip_title"
	        label="会员"
	        width="160">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div>会员：{{scope.row.vip_title}}</div>
		      	<div v-if="scope.row.company_vip_level>0">到期时间：{{scope.row.company_vip_time}}</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="jobs_count"
	        label="职位数"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="企业认证"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button v-for="v in attestation" :type="v.type" size="minism"
		      		v-if="scope.row.attestation==v.value"
		      		@click="window.open('/company/attestation?uid='+scope.row.uid)">{{v.title}}</el-button>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="nickname"
	        label="所有者"
	        width="120">
	      </el-table-column>
	      <el-table-column
	      	prop="crm_follow_up"
	        label="最近跟进"
	        min-width="180">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div :class="'tag-'+scope.row.tag_type">标签：{{scope.row.tag_text}}</div>
		      	<div>时间：{{scope.row.last_follow_up_time}}</div>
		      	<div>结果：{{scope.row.crm_follow_up.status}}</div>
		      	<div>内容：{{scope.row.crm_follow_up.content}}</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="120">
		      <template slot-scope="scope">
		        <el-button
		            type="success"
		            plain
		            round
		            size="minism"
		            @click="openFollowUp(scope)">
		            跟进
		        </el-button>
		        <el-button
		            type="primary"
		            plain
		            round
		            size="minism"
		            icon="el-icon-more"
		            @click="openFollowUp(scope,'customer')">
		        </el-button>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
<el-drawer
  title="我是标题"
  :visible.sync="drawerHandle"
  :with-header="false"
  :before-close="closeDrawerHandle">
  	<div class="wrap h-100">
  		<div class="px-2">
		  	<el-tabs v-model="activeName">
			    <el-tab-pane label="跟进" name="follow_up"></el-tab-pane>
			    <el-tab-pane label="移交" name="transfer"></el-tab-pane>
			    <el-tab-pane label="所有者变更记录" name="adviser"></el-tab-pane>
			    <el-tab-pane label="客户信息" name="customer"></el-tab-pane>
			</el-tabs>	
		</div>
		<div class="flex1 p-2 wrap" v-if="activeName=='follow_up'&&drawerHandleScope.row">
			<el-form :model="follow_up" @submit.native.prevent="submitFollowUp" ref="follow_up" label-width="140px" label-position="top" class="flex1 overflow-auto">
			  <el-form-item label="客户">
				{{drawerHandleScope.row.title}}
			  </el-form-item>
			  <el-form-item label="跟进方式与结果"
			  prop="status"
			  :rules="[
			      { required: true, message: '请选择跟进方式与结果', trigger: 'change' },
			   ]">
				  <el-select
				    v-model="follow_up.status"
				    filterable
				    placeholder="跟进方式与结果"
				    clearable
				    class="w-75">
				    <el-option
				      v-for="item in FollowUpStatus"
				      :key="item.value"
				      :label="item.title"
				      :value="item.value">
				    </el-option>
				  </el-select>
			  </el-form-item>
			  <el-form-item label="跟进内容"
			  prop="content"
			  :rules="[
			      { required: true, message: '请输入跟进内容', trigger: 'blur' },
			   ]">
			    <el-input
				  type="textarea"
				  :autosize="{ minRows: 6, maxRows: 20}"
				  placeholder="请输入内容"
				  v-model="follow_up.content">
			  </el-form-item>
			  <el-form-item label="下次跟进时间" prop="next_follow_up_time">
			    <el-date-picker
			      v-model="follow_up.next_follow_up_time"
			      type="datetime"
			      placeholder="选择日期时间"
			      value-format="timestamp"
			      :picker-options="pickerOptions"
				    class="w-75">
			    </el-date-picker>
			  </el-form-item>
			</el-form>
			
			<div class="text-right">
			    <el-button type="primary" @click="submitFollowUp" :loading="follow_up.ajax">{{follow_up.ajax?'提交中...':'提 交'}}</el-button>
			</div>
		</div>
		<div class="flex1 p-2 wrap" v-if="activeName=='adviser'&&drawerHandleScope.row">
		<el-table
	      	:data="drawerHandleScope.row.adviser_log"
    		style="width: 100%;">
		  <el-table-column
	      	prop="nickname"
	        label="操作人">
		  </el-table-column>
	      <el-table-column
	      	prop="adviser"
	        label="所有者">
	      </el-table-column>
	      <el-table-column
	        label="操作"
	        width="100">
			  <template slot-scope="scope">
			  	{{scope.row.status?'加入':'释放'}}
			  </template>
	      </el-table-column>
	      <el-table-column
	      	prop="create_time"
	        label="时间"
	        width="180">
	      </el-table-column>
	    </el-table>
		</div>
		<div class="flex1 p-2 wrap" v-if="activeName=='customer'&&drawerHandleScope.row">
			<el-form :model="customer" @submit.native.prevent="submitFollowUp" ref="customer" label-width="140px" label-position="top" class="flex1 overflow-auto">
			  <el-form-item label="客户">
				{{drawerHandleScope.row.title}}
			  </el-form-item>
			  <el-form-item label="标签" prop="tag">
				  <el-select
				    v-model="customer.tag"
				    filterable
				    placeholder="客户标签"
				    clearable
				    class="w-75">
				    <el-option
				      :class="'tag-'+item.type"
				      v-for="item in CrmTag"
				      :key="item.value"
				      :label="item.title"
				      :value="item.value">
				    </el-option>
				  </el-select>
			  </el-form-item>
			  <el-form-item label="客户联系人"
			  prop="customer"
			  :rules="[
			      { required: true, message: '请输入客户联系人', trigger: 'blur' },
			   ]">
			   <el-input v-model="customer.customer"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="手机号" prop="customer_mobile">
			   <el-input v-model="customer.customer_mobile"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="座机" prop="customer_tel">
			   <el-input v-model="customer.customer_tel"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="邮箱" prop="customer_email">
			   <el-input v-model="customer.customer_email"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="微信号" prop="customer_wechat">
			   <el-input v-model="customer.customer_wechat"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="QQ" prop="customer_qq">
			   <el-input v-model="customer.customer_qq"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="其他" prop="customer_other">
			   <el-input v-model="customer.customer_other"
				    class="w-75"></el-input>
			  </el-form-item>
			  <el-form-item label="下次跟进时间" prop="next_follow_up_time">
			    <el-date-picker
			      v-model="customer.next_follow_up_time"
			      type="datetime"
			      placeholder="选择日期时间"
			      value-format="timestamp"
			      :picker-options="pickerOptions"
				    class="w-75">
			    </el-date-picker>
			  </el-form-item>
			</el-form>
			<div class="flex">
			    <el-button type="danger" @click="cancelAdviser" :loading="customer.ajax">{{customer.ajax?'释放中...':'释 放'}}</el-button>
			    <div class="flex-1"></div>
			    <el-button type="primary" @click="submitMyCustomer" :loading="customer.ajax">{{customer.ajax?'保存中...':'保 存'}}</el-button>
			</div>
		</div>
		<div class="flex1 p-2 wrap" v-if="activeName=='transfer'&&drawerHandleScope.row">
			<div class="flex1 p-3" style="overflow-y: auto;">
				<div class="flex flex-center border border-lg rounded-lg mb-3 p-3 pointer"
				v-for="v in admin"
				:class="{'border-primary':adviser.id==v.id}"
				@click="adviser=v">
					<el-image
					  	v-if="v.headimg" 
					    style="width: 60px; height: 60px"
					    lazy
					    class="rounded-circle mr-2"
					    :src="v.headimg" 
					    :preview-src-list="[v.headimg]">
					</el-image>
	  				<div class="flex-1">
				      	<el-link
				      	:underline="false">{{v.nickname}}</el-link>
	  				</div>
	  				<div class="text-secondary small" v-if="v.adviser_default">默认</div>
				</div>
			</div>
			<div class="flex">
			    <div class="flex-1"></div>
				{eq name=":request()->action()" value="customer"}
			    <el-button type="primary" @click="transferAdviser" :loading="customer.ajax">{{customer.ajax?'移交中...':'移 交'}}</el-button>
			    {else/}
			    <el-button type="primary" @click="transferSelfAdviser" :loading="customer.ajax">{{customer.ajax?'移交中...':'移 交'}}</el-button>
			    {/eq}
			</div>
		</div>
  	</div>
</el-drawer>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="admin"}
	var admin=[];
	{else/}
	var admin={:json_encode($admin,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="attestation"}
	var attestation=[];
	{else/}
	var attestation={:json_encode($attestation,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="CrmTag"}
	var CrmTag=[];
	{else/}
	var CrmTag={:json_encode($CrmTag,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="FollowUpStatus"}
	var FollowUpStatus=[];
	{else/}
	var FollowUpStatus={:json_encode($FollowUpStatus,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="vip"}
	var vip=[];
	{else/}
	var vip={:json_encode($vip,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var loading=null;
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			seniorSearch:false,
			labelPosition:'right',
			activeName:'follow_up',
			admin:admin,
			attestation:attestation,
			CrmTag:CrmTag,
			FollowUpStatus:FollowUpStatus,
			vip:vip,
			drawerHandle:false,
			drawerHandleScope:{},
			multipleSelection:[],
			adviser:{id:0},
			follow_up:{
				ajax:false,
				crm_id:'',
				status:'',
				content:'',
				next_follow_up_time:'',
			},
			customer:{
				ajax:false,
				id:'',
				customer:'',
				customer_mobile:'',
				customer_tel:'',
				customer_email:'',
				customer_wechat:'',
				customer_qq:'',
				customer_other:'',
				tag:'',
				next_follow_up_time:'',
			},
	        pickerOptions: {
	          shortcuts: [{
	            text: '今天',
	            onClick(picker) {
	              picker.$emit('pick', new Date());
	            }
	          }, {
	            text: '明天',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24);
	              picker.$emit('pick', date);
	            }
	          }, {
	            text: '三天后',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24 * 3);
	              picker.$emit('pick', date);
	            }
	          }, {
	            text: '五天后',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24 * 5);
	              picker.$emit('pick', date);
	            }
	          }, {
	            text: '一周后',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
	              picker.$emit('pick', date);
	            }
	          }, {
	            text: '15天后',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24 * 15);
	              picker.$emit('pick', date);
	            }
	          }, {
	            text: '30天后',
	            onClick(picker) {
	              const date = new Date();
	              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
	              picker.$emit('pick', date);
	            }
	          }],
	          disabledDate:(event)=>{
	            const date = new Date();
	          	return date.getTime()>event.getTime();
	          }
	        },
			search:{
				search_type:'id',
				key:'',
				attestation:'all',
				vip_level:'all',
				adviser_id:'',
				tag:{:request()->get('tag',"'all'")},
				follow_up:'{:request()->get('follow_up','all')}',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	closeDrawerHandle(done){
	    		if(this.follow_up.ajax||this.customer.ajax)return;
	    		this.drawerHandleScope={};
	    		this.adviser={id:0};
				this.resetForm(this.activeName);
	    		this.activeName='follow_up';
	    		done();
	    	},
	    	openFollowUp(scope,activeName){
	    		if(activeName)
	    			this.activeName=activeName;
	    		this.drawerHandleScope=scope;
	    		this.follow_up.crm_id=scope.row.id;
	    		this.customer.id=scope.row.id;
				this.customer.customer=scope.row.customer;
				this.customer.customer_mobile=scope.row.customer_mobile;
				this.customer.customer_tel=scope.row.customer_tel;
				this.customer.customer_email=scope.row.customer_email;
				this.customer.customer_wechat=scope.row.customer_wechat;
				this.customer.customer_qq=scope.row.customer_qq;
				this.customer.customer_other=scope.row.customer_other;
				this.customer.tag=scope.row.tag;
				if(scope.row.next_follow_up_time)
				this.customer.next_follow_up_time=scope.row.next_follow_up_time*1000;
	    		this.drawerHandle=true;
	    	},
		    toggleSelection(rows) {
		        if (rows) {
		          rows.forEach(row => {
		            this.$refs.tableList.toggleRowSelection(row);
		          });
		        } else {
		          this.$refs.tableList.clearSelection();
		        }
		    },
		    handleSelectionChange(val) {
		        this.multipleSelection = val;
		    },
		    submitFollowUp(){
		    	this.$refs.follow_up.validate((valid) => {
		          if (valid) {
		      		var _this=this;
		      		_this.follow_up.ajax=true;
					$.ajax({
						url:'/crm/my_follow_up',
						type:'post',
						data:_this.follow_up,
						dataType:'json',
						error:function(err){
		      				_this.follow_up.ajax=false;
							XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
		      				_this.follow_up.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									_this.drawerHandle=false;
									_this.drawerHandleScope.row.last_follow_up_time=ret.time;
									if(_this.follow_up.next_follow_up_time)
									_this.drawerHandleScope.row.next_follow_up_time=XYBase.Date.date('Y-m-d H:i:s',_this.follow_up.next_follow_up_time);
									for (x in _this.FollowUpStatus) {
										if(_this.FollowUpStatus[x].value==_this.follow_up.status){
										_this.drawerHandleScope.row.crm_follow_up.status=_this.FollowUpStatus[x].title;
										break;
										}
									}
									_this.drawerHandleScope.row.crm_follow_up.content=_this.follow_up.content;
									_this.resetForm('follow_up');
								}else{
									XYBase.msg(ret.msg);
								}
							}else{
								XYBase.error(XYBase.config.system_network_error);
							}
						}
					});
		          } else {
		            XYBase.msg('请先把表单填写完整。');
		            return false;
		          }
		        });
		    },
		    submitMyCustomer(){
		    	this.$refs.customer.validate((valid) => {
		          if (valid) {
		      		var _this=this;
		      		_this.customer.ajax=true;
					$.ajax({
						url:'/crm/edit_customer',
						type:'post',
						data:_this.customer,
						dataType:'json',
						error:function(err){
		      				_this.customer.ajax=false;
							XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
		      				_this.customer.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									for (x in _this.CrmTag) {
										if(_this.CrmTag[x].value==_this.customer.tag){
										_this.drawerHandleScope.row.tag_text=_this.CrmTag[x].title;
										_this.drawerHandleScope.row.tag_type=_this.CrmTag[x].type;
										break;
										}
									}
									_this.drawerHandleScope.row.customer=_this.customer.customer;
									_this.drawerHandleScope.row.customer_mobile=_this.customer.customer_mobile;
									_this.drawerHandleScope.row.customer_tel=_this.customer.customer_tel;
									_this.drawerHandleScope.row.customer_email=_this.customer.customer_email;
									_this.drawerHandleScope.row.customer_wechat=_this.customer.customer_wechat;
									_this.drawerHandleScope.row.customer_qq=_this.customer.customer_qq;
									_this.drawerHandleScope.row.customer_other=_this.customer.customer_other;
									_this.drawerHandleScope.row.tag=_this.customer.tag;
									_this.drawerHandleScope.row.next_follow_up_time=_this.customer.next_follow_up_time/1000;
									XYBase.success(ret.msg);
								}else{
									XYBase.msg(ret.msg);
								}
							}else{
								XYBase.error(XYBase.config.system_network_error);
							}
						}
					});
		          } else {
		            XYBase.msg('请先把表单填写完整。');
		            return false;
		          }
		        });
		    },
		    cancelAdviser() {
	      		var _this=this;
		        this.$confirm('确定释放【'+_this.drawerHandleScope.row.title+'】客户吗？释放后客户将加入公共池。', '提示', {
		        	dangerouslyUseHTMLString:true,
		          confirmButtonText: '释放',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
	      			_this.customer.ajax=true;
					$.ajax({
						url:'/crm/cancelAdviser/'+_this.drawerHandleScope.row.company_id,
						type:'get',
						data:{},
						dataType:'json',
						error:function(err){
	      					_this.customer.ajax=false;
				          	XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
	      					_this.customer.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									_this.tableData.splice(_this.drawerHandleScope.$index,1);
									_this.closeDrawerHandle(function(){
										_this.drawerHandle=false;
									})
									XYBase.success(ret.msg);
								}else XYBase.msg(ret.msg);
							}else XYBase.error(XYBase.config.system_network_error);
						}
					})
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
		    },
		    transferAdviser(){
	      		var _this=this;
	      		if (!_this.adviser.id)return XYBase.msg('请选择移交对象');
		        this.$confirm('确定移交【'+_this.drawerHandleScope.row.title+'】客户吗？', '提示', {
		        	dangerouslyUseHTMLString:true,
		          confirmButtonText: '移交',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
	      			_this.customer.ajax=true;
					$.ajax({
						url:'/crm/transferAdviser/'+_this.drawerHandleScope.row.id+'/'+_this.adviser.id,
						type:'get',
						data:{},
						dataType:'json',
						error:function(err){
	      					_this.customer.ajax=false;
				          	XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
	      					_this.customer.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									_this.drawerHandleScope.row.nickname=_this.adviser.nickname;
									_this.closeDrawerHandle(function(){
										_this.drawerHandle=false;
									})
									XYBase.success(ret.msg);
								}else XYBase.msg(ret.msg);
							}else XYBase.error(XYBase.config.system_network_error);
						}
					})
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
		    },
		    transferSelfAdviser(){
	      		var _this=this;
	      		if (!_this.adviser.id)return XYBase.msg('请选择移交对象');
		        this.$confirm('确定移交【'+_this.drawerHandleScope.row.title+'】客户吗？', '提示', {
		        	dangerouslyUseHTMLString:true,
		          confirmButtonText: '移交',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
	      			_this.customer.ajax=true;
					$.ajax({
						url:'/crm/transferSelfAdviser/'+_this.drawerHandleScope.row.id+'/'+_this.adviser.id,
						type:'get',
						data:{},
						dataType:'json',
						error:function(err){
	      					_this.customer.ajax=false;
				          	XYBase.error(XYBase.config.system_network_error);
						},
						success:function(ret){
	      					_this.customer.ajax=false;
							if (ret) {
								if (ret.code === 0) {
									_this.tableData.splice(_this.drawerHandleScope.$index,1);
									_this.closeDrawerHandle(function(){
										_this.drawerHandle=false;
									})
									XYBase.success(ret.msg);
								}else XYBase.msg(ret.msg);
							}else XYBase.error(XYBase.config.system_network_error);
						}
					})
		        }).catch(() => {
					XYBase.msg('已取消');
		        });
		    },
	    	getSearchType(){
	    		var text='公司ID';
	    		switch(this.search.search_type){
	    			case 'id':
	    				text='公司ID';
	    				break;
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'uscc':
	    				text='统一社会信用代码';
	    				break;
	    			case 'company_name':
	    				text='公司名';
	    				break;
	    			case 'customer_mobile':
	    				text='手机号';
	    				break;
	    			case 'customer_tel':
	    				text='座机';
	    				break;
	    			case 'customer_email':
	    				text='邮箱';
	    				break;
	    			case 'customer_wechat':
	    				text='微信号';
	    				break;
	    			case 'customer_qq':
	    				text='QQ';
	    				break;
	    		}
	    		return text;
	    	},
			resetForm:function(formName) {
				if(this.$refs[formName])
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{include file="business"/}
{/block}